//
//  LXCommissionTeamTBVC.m
//  绿稀全球购
//
//  Created by 王敏 on 16/6/10.
//  Copyright © 2016年 SJT. All rights reserved.
//

#import "LXCommissionTeamController.h"
#import "LXTeamCell.h"
@interface LXCommissionTeamController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView * tableView;
@property(nonatomic,strong)NSArray * teams;

@property(nonatomic,assign)NSInteger teamCount;
@end

@implementation LXCommissionTeamController
NSString * const TeamCellID = @"TeamCell";
NSInteger cells = 10;
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpTableView];
    [self loadData];

}


-(void)loadData
{
    self.teamCount = 10;
}

#pragma mark - 设置导航栏
-(void)setUpNavi{
    [super setUpNavi];
    self.navigationItem.title = @"我的团队";
}

#pragma mark - 返回按钮点击
-(void)backButtonClick:(UIButton*)button{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)setUpTableView{
    UITableView * tableView   = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenSize.width, ScreenSize.height) style:UITableViewStyleGrouped];
    
    tableView.delegate        = self;
    tableView.dataSource      = self;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    tableView.sectionFooterHeight = 40;
    tableView.contentInset = UIEdgeInsetsMake(44, 0, 0, 0);
    [self.view addSubview:tableView];
    self.tableView            = tableView;
    [tableView registerClass:[LXTeamCell class] forCellReuseIdentifier:TeamCellID];
    
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setUpNavi];
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.teamCount;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LXTeamCell * cell = [tableView dequeueReusableCellWithIdentifier:TeamCellID];
    cell.showSubTeam = self.showSubTeam;
    cell.model = self.teams[indexPath.row];
    
    cell.backgroundImageView.transform = CGAffineTransformIdentity;
    [cell.backgroundImageView addRadius:0];
    cell.enableUnderLine = NO;
    [self addCellHeight:cell.cellHeight indexPath:indexPath];
    if(self.teamCount == 0){
        
    }else if(self.teamCount == 1){
        cell.backgroundImage = [UIImage imageWithColor:[UIColor whiteColor] size:CGSizeMake(ScreenWidth-2*globalMargin, cell.cellHeight)];
        [cell.backgroundImageView addRadius:10];
    }else if (self.teamCount == 2){
        if(indexPath.row == 0){
            cell.backgroundImage = [UIImage imageNamed:@"brokerage_bg02"];
            cell.backgroundImageView.transform = CGAffineTransformRotate(cell.backgroundImageView.transform, M_PI);
            cell.enableUnderLine = YES;
        }else{
            cell.backgroundImage = [UIImage imageNamed:@"brokerage_bg02"];
        }
    }
    else{
        if(indexPath.row == 0){
            cell.backgroundImage = [UIImage imageNamed:@"brokerage_bg02"];
            cell.backgroundImageView.
            transform = CGAffineTransformRotate(cell.backgroundImageView.transform, M_PI);
            cell.enableUnderLine = YES;
        }else if(indexPath.row == self.teamCount-1){
            cell.backgroundImage = [UIImage imageNamed:@"brokerage_bg02"];
            cell.enableUnderLine = NO;
        }else{
            cell.backgroundImage = [UIImage imageWithColor:[UIColor whiteColor] size:CGSizeMake(ScreenWidth-2*globalMargin, cell.cellHeight)];
            cell.enableUnderLine = YES;
        }
    }
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [self cellHeightForIndexPath:indexPath];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

}



-(void)dealloc{
//    NSLog(@"%s",__func__);
}


-(void)viewDidLayoutSubviews
{
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
    }
    
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tableView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
    }
}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}







@end
